/**
 * ¸各种疑难杂症测试
 * @author smallcatX0 
 * @date    2018-01-11 15:18:20
 * @version $Id$
 */
import java.util.Arrays;

public class test  {
    public static void main(String[] args) {

    	/*String a = "heykui";
    	// 字符串常量 就是string匿名对象
		System.out.println("heykui".equals(a));
		System.out.println("heykui".length());
		*/
		int [] arr = {1,6,8,3,9,5,2,89,45,11};
		System.out.println(binSearch(arr,6));
		System.out.println(Arrays.toString(arr));
	}
	public static int binSearch(int[] a,int val){
		Arrays.sort(a);
		int min = 0;
		int max = a.length - 1;
		int now = (max+min)/2;
		while(a[now] != val){
			if (min>max) return -1;
			if (a[now]<val) min = now + 1;
			else if (a[now] > val) max = now - 1;
			now = (max+min)/2;
		}
		// for (int i :a ) System.out.print(i+" ");
		return now;
	}
}